<template>
  <el-dialog
    title="简答题"
    :visible.sync="editVisible"
    width="50%"
    :show-close="false"
    :close-on-click-modal="false">
    <el-form :model="editFormData" status-icon  ref="editFormData" label-width="60px" class="demo-ruleForm">
      <el-row>
        <el-col :span="24">
          <el-form-item label="题目:" prop="sa_title" :rules="[{required: true, message: '不能为空', trigger: 'change' }]">
            <el-input type="textarea" v-model="editFormData.sa_title" auto-complete="off"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="答案:" prop="shortAnswerAns.saa_answer" :rules="[{required: true, message: '不能为空', trigger: 'change' }]">
            <el-input type="textarea" v-model="editFormData.shortAnswerAns.saa_answer" auto-complete="off"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
       <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog" size="mini">取 消</el-button>
        <el-button type="primary" @click="submitData" size="mini">确 定</el-button>
      </span>
  </el-dialog>
</template>
<script>
  import {updateShortAnswer} from '@/api/questions'
export default{
    props:["showEditVisible","rowData"],
    mounted(){
        this.editFormData = JSON.parse(JSON.stringify(this.rowData))
    },
    data(){
        return {
          editVisible:this.showEditVisible,
          editFormData:{
            shortAnswerAns:{
              saa_answer:null
            }
          },
        }
    },

    methods:{
      submitData(){
        this.$refs["editFormData"].validate((valid) =>{
            if(valid){
              updateShortAnswer(this.editFormData).then(res=>{
                if(res.code == 200){
                  this.$message({
                    type: 'success',
                    message: '修改成功'
                  });
                  this.closeDialog();
                }else{
                  this.$message({
                    type: 'error',
                    message: '修改失败'
                  });
                }
              })
            }
        });

      },
      closeDialog(){
          this.editVisible = false;
          this.$emit("closeAddDialog","edit");
      },
    }
}

</script>
